﻿/* Initialise the display. */
function init()
{

	if ( wave && wave.isInWaveContainer() )
	{
		wave.setStateCallback( stateUpdated );
	}

	_IG_AdjustIFrameHeight();								   			
	//	RefreshData(0);//get the current games
	//	RefreshData(1);//get the results
	//	RefreshData(2);//get the recommendations
	//	RefreshData(3);//get the current time
	/* Set the page displayed according to the current play mode */

	//setTimeout("getPage()",400);
	setTimeout("firstInit()",400);
	setTimeout("ResultsToState()",400);
	setTimeout("RecommendationsToState()",2000);

	gadgets.window.adjustHeight();
}


gadgets.util.registerOnLoadHandler( init );

/* After the state has changed, refresh the display. */
function stateUpdated()
{
	var game = gameState();		   
	refreshGrid( game );
	refreshMoves( game );
	refreshAgreement(); //<effi> refresh the agreement bar
	refreshAgreementDivs();//<effi> refresh the agreement personal Divs
	refreshCost();
	RefreshGames();
	//RefreshRec();  <oren> this function is no longer needed as the rec's are being fetched on the fly
	//getLastWeekInfo(); <Gili> this funtion will be triggred from the last week button.
	refreshTalkBacks(); //<effi> hope all these changes arent fucking up the code...
	gadgets.window.adjustHeight();
}

// the first call to init needs a NewForm() call
function firstInit(){
	var IsPlaying = parseInt(wave.getState().get("IsPlaying"));
	if(!IsPlaying){
		curTime = currentTime();
		if(	(curTime.getDay() ==0) ||
			((curTime.getDay() ==1) && (curTime.getHours()< 16)) ||
			((curTime.getDay() ==6) && (curTime.getHours()> 11))) { 

			RefreshData(0);
			RefreshData(4);
		}
		getWaveIDfromDB();
		NewForm(0);
	}
}

